package cp.remote.activity;

import cp.remote.R;
import cp.remote.config.NetworkConfig;
import cp.remote.network.TaskSwitch;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public abstract class Main_Activity extends Activity {

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Create Options menu for all Activitys
        if (NetworkConfig.nettask != null
                && NetworkConfig.nettask.isConnected()) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.menu, menu);
        }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Option selcetion
        Intent i = new Intent(this, Load_Activity.class);
        switch (item.getItemId()) {
        case R.id.avoid_barriers:
            i.putExtra("Activity", Activitys.BARRIER);
            i.putExtra("Command", TaskSwitch.BARRIER.name());
            break;
        case R.id.people_tracking:
            i.putExtra("Activity", Activitys.PEOPLE);
            i.putExtra("Command", TaskSwitch.PERSON.name());
            break;
        case R.id.remote:
            i.putExtra("Activity", Activitys.REMOTE);
            i.putExtra("Command", TaskSwitch.MANUAL.name());
            break;
        case R.id.config:
            NetworkConfig.nettask.send(TaskSwitch.STOP);
            i = new Intent(this, Config_Activity.class);
            break;
        default:
            return super.onOptionsItemSelected(item);
        }
        startActivity(i);
        customStop();

        finish();
        return true;
    }

    abstract public void customStop();
    abstract public void setStateText(String text);
}
